package vno.sci.window
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import org.aswing.AsWingManager;
	import org.aswing.AssetBackground;
	import org.aswing.BoxLayout;
	import org.aswing.EmptyLayout;
	import org.aswing.JButton;
	import org.aswing.JFrame;
	import org.aswing.JLabel;
	import org.aswing.JPanel;
	import org.aswing.JPopup;
	import org.aswing.JScrollPane;
	import org.aswing.JTextArea;
	import org.aswing.JWindow;
	import org.aswing.event.FrameEvent;
	import org.aswing.event.ResizedEvent;
	
	import vno.fux.res.pool.BitmapAttacher;
	import vno.sci.event.MonologEvent;
	import vno.sci.window.Monolog;
	import vno.sci.window.MyButton;
	

	/**
	 * 注意,getter和setter方法不全，变量暂时使用公有.
	 * 
	 */
	
	public class MonologModel extends EventDispatcher
	{
		public var titleP:String = "title";
		public var textP:String = "text";
		public var htmlTextP:String = "";
		public var windowWidthP:int = 300;
		public var windowHeightP:int = 200;
		public var textWidthP:int = 300;
		public var textHeightP:int = 180;
		public var xP:Number = 0;
		public var yP:Number = 0;
		public var visibleP:Boolean = true;
		/**
		 * textRange = textWidth/windowWidth; 
		 */		
		public var textRange:Number = 0.8;
		public var buttonHeight:int = 30;
		public var titleHeight:int = 50;
		
		
		public function changeData(a:Object):void
		{
			
			if(a is XML)
			{
				if (a.hasOwnProperty("title"))
				{
					titleP = a.title;
				}
				if (a.hasOwnProperty("text"))
				{
					textP = a.text;
				}
				if (a.hasOwnProperty("htmlText"))
				{
					htmlTextP = a.htmlText;
				}
				if (a.hasOwnProperty("buttonHeight"))
				{
					buttonHeight = a.buttonHeight;
				}
				if (a.hasOwnProperty("titleHeight"))
				{
					titleHeight = a.titleHeight;
				}
				if (a.hasOwnProperty("windowWidth"))
				{
					windowWidthP = a.windowWidth;
				}
				if (a.hasOwnProperty("windowHeight"))
				{
					windowHeightP = a.windowHeight;
				}
				if (a.hasOwnProperty("textWidth"))
				{
					textWidthP = a.textWidth;
					textRange = textWidthP / windowWidthP;
				}
				if (a.hasOwnProperty("textHeight"))
				{
					textHeightP = a.textHeight;
				}
				if (a.hasOwnProperty("x"))
				{
					xP = a.x;
				}
				if (a.hasOwnProperty("y"))
				{
					yP = a.y;
				}
				if (a.hasOwnProperty("visible"))
				{
					visibleP = a.visible;
				}		
				this.forceUpdate();
				return;
			}
			if (a["title"])
			{
				titleP = a["title"];
			}
			if (a["text"])
			{
				textP = a["text"];
				if (a["htmlText"])
				{
					htmlTextP = a["htmlText"];
				}
				else htmlTextP = "";
			}
			if (a["htmlText"])
			{
				htmlTextP = a["htmlText"];
			}
			if (a["titleHeight"])
			{
				titleHeight = a["titleHeight"];
			}
			if (a["buttonHeight"])
			{
				buttonHeight = a["buttonHeight"];
			}
			if (a["windowWidth"])
			{
				windowWidthP = a["windowWidth"];
			}
			if (a["windowHeight"])
			{
				windowHeightP = a["windowHeight"];
			}
			if (a["textWidth"])
			{
				textWidthP = a["textWidth"];
				textRange = textWidthP / windowWidthP;
			}
			if (a["textHeight"])
			{
				textHeightP = a["textHeight"];
			}
			if (a["x"])
			{
				xP = a["x"];
			}
			if (a["y"])
			{
				yP = a["y"];
			}
			if (a["visible"] is Boolean)
			{
				visibleP = a["visible"];
			}
			this.forceUpdate();
		}
		
		public function get title():String
		{
			return titleP;
		}
		public function get text():String
		{
			return textP;
		}
		public function get htmlText():String
		{
			return htmlTextP;
		}
		public function get width():int
		{
			return windowWidthP;
		}
		public function get height():int
		{
			return windowHeightP;
		}
		public function get x():Number
		{
			return xP;
		}
		public function get y():Number
		{
			return yP;
		}
		public function get visible():Boolean
		{
			return visibleP;
		}
		
		//		public function set title(_title:String):void
		//		{
		//			titleP = _title;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set text(_text:String):void
		//		{
		//			textP = _text;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set htmlText(_htmlText:Boolean):void
		//		{
		//			htmlTextP = _htmlText;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set width(width_:int):void
		//		{
		//			windowWidthP = width_;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set height(height_:int):void
		//		{
		//			windowHeightP = height_;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set x(x_:Number):void
		//		{
		//			xP = x_;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set y(y_:Number):void
		//		{
		//			yP = y_;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}public function set visible(visible_:Boolean):void
		//		{
		//			visibleP = visible_;
		//			dispatchEvent(new Event(Event.CHANGE));
		//		}
		
		public function forceUpdate():void
		{
			dispatchEvent(new Event(Event.CHANGE));
		}	
		/**
		 * 
		 * @param a
		 * a contains data, which can be an associated array or an XML file. 
		 */			
		public function MonologModel(a:Object)
		{
			super();
			if(a is XML)
			{
				if (a.hasOwnProperty("title"))
				{
					titleP = a.title;
				}
				if (a.hasOwnProperty("text"))
				{
					textP = a.text;
				}
				if (a.hasOwnProperty("htmlText"))
				{
					htmlTextP = a.htmlText;
				}
				if (a.hasOwnProperty("buttonHeight"))
				{
					buttonHeight = a.buttonHeight;
				}
				if (a.hasOwnProperty("titleHeight"))
				{
					titleHeight = a.titleHeight;
				}
				if (a.hasOwnProperty("windowWidth"))
				{
					windowWidthP = a.windowWidth;
				}
				if (a.hasOwnProperty("windowHeight"))
				{
					windowHeightP = a.windowHeight;
				}
				if (a.hasOwnProperty("textWidth"))
				{
					textWidthP = a.textWidth;
					textRange = textWidthP / windowWidthP;
				}
				if (a.hasOwnProperty("textHeight"))
				{
					textHeightP = a.textHeight;
				}
				if (a.hasOwnProperty("x"))
				{
					xP = a.x;
				}
				if (a.hasOwnProperty("y"))
				{
					yP = a.y;
				}
				if (a.hasOwnProperty("visible"))
				{
					visibleP = a.visible;
				}		
				this.forceUpdate();
				return;
			}
			else if (a != null)
			{
				if (a["title"])
				{
					titleP = a["title"];
				}
				if (a["text"])
				{
					textP = a["text"];
					if (a["htmlText"])
					{
						htmlTextP = a["htmlText"];
					}
					else htmlTextP = "";
				}
				if (a["htmlText"])
				{
					htmlTextP = a["htmlText"];
				}
				if (a["titleHeight"])
				{
					titleHeight = a["titleHeight"];
				}
				if (a["buttonHeight"])
				{
					buttonHeight = a["buttonHeight"];
				}
				if (a["windowWidth"])
				{
					windowWidthP = a["windowWidth"];
				}
				if (a["windowHeight"])
				{
					windowHeightP = a["windowHeight"];
				}
				if (a["textWidth"])
				{
					textWidthP = a["textWidth"];
					textRange = textWidthP / windowWidthP;
				}
				if (a["textHeight"])
				{
					textHeightP = a["textHeight"];
				}
				if (a["x"])
				{
					xP = a["x"];
				}
				if (a["y"])
				{
					yP = a["y"];
				}
				if (a["visible"])
				{
					visibleP = a["visible"];
				}
			}
		}
	}
}